﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace testWebAPI.Controllers;

[ApiController]
[Route("testApi/[Controller]/[action]")]
public class WeatherForecastController : ControllerBase
{
  readonly ILogger<WeatherForecastController> _logger;
  public WeatherForecastController(ILogger<WeatherForecastController> logger) =>
    this._logger = logger;

  [HttpGet]
  public String[] GetFileNames()
  {
    String[] fileList = Directory.GetFiles(@".\trainingDigits", "*.txt");
    return (fileList.Select(item =>
      item.Replace(@".\trainingDigits\", "")).ToArray());
  }

  [HttpGet]
  public async Task<String[]> GetFileNamesByNumberAndParam(string number, string param) =>
    await System.IO.File.ReadAllLinesAsync(@".\trainingDigits\" + $"{number}_{param}.txt");
}



